/****************************************************************************
 * Copyright (C) 2009-2010 SciTouch LLC
 * 
 * This file is part of Indigo toolkit.
 * 
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 3 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 ***************************************************************************/

#ifndef __molecule_tautomer_matcher__
#define __molecule_tautomer_matcher__

#include "graph/embedding_enumerator.h"
#include "molecule/molecule_tautomer.h"

class Molecule;
class GraphHighlighting;
class AromaticityMatcher;

class MoleculeTautomerMatcher
{
public:
   DEF_ERROR("molecule tautomer matcher");

   GraphHighlighting *highlighting;

   MoleculeTautomerMatcher (const Molecule &target);

   void setQuery (const Molecule &query);

   void setRulesList (const PtrArray<TautomerRule> *rules_list);
   void setRules (int rules_set, bool force_hydrogens, bool ring_chain);

   bool findExact ();
   bool findSubstructure ();

   static void parseConditions (const char *tautomer_text, int &rules, bool &force_hydrogens, bool &ring_chain);

   static int countNonHydrogens (const Molecule &molecule);

protected:

   bool _find (bool substructure);

   static bool _checkRules (TautomerSearchContext &context, int first1, int first2, int last1, int last2);


   bool _force_hydrogens;
   bool _ring_chain;
   int  _rules;

   const PtrArray<TautomerRule> *_rules_list;
   AutoPtr<TautomerSearchContext> _context;
   const Molecule &_target_src;
   TL_CP_DECL(TautomerSuperStructure, _target);
   TL_CP_DECL(Molecule, _query);

   Obj<GraphDecomposer> _query_decomposer;
   Obj<GraphDecomposer> _target_decomposer;
};

#endif
